package com.tuananh.radnom.gwt.shared.event;

import java.util.ArrayList;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.tuananh.radnom.gwt.shared.dto.MyBaseDTO;
import com.tuananh.radnom.gwt.shared.dto.NetNodeDTO;

public class NetNodeTreeEvent extends GwtEvent<NetNodeTreeEventHandler> {
	public static enum NodeTreeEventType {
		FETCH, ADD, SELECT
	}

	NodeTreeEventType eventType;
	ArrayList<NetNodeDTO> listNode = null;
	NetNodeDTO addedNode = null;
	MyBaseDTO selectedNode = null;

	public ArrayList<NetNodeDTO> getListNode() {
		return listNode;
	}

	public NetNodeDTO getAddedNode() {
		return addedNode;
	}

	public MyBaseDTO getSelectedNode() {
		return selectedNode;
	}

	public NetNodeTreeEvent() {

	}

	public NetNodeTreeEvent(NodeTreeEventType type, ArrayList<NetNodeDTO> listNode,
			NetNodeDTO addedNode, MyBaseDTO selectedNode) {
		this.listNode = listNode;
		this.addedNode = addedNode;
		this.selectedNode = selectedNode;
		this.eventType = type;
	}

	public static final Type<NetNodeTreeEventHandler> TYPE = new Type<NetNodeTreeEventHandler>();

	@Override
	public com.google.gwt.event.shared.GwtEvent.Type<NetNodeTreeEventHandler> getAssociatedType() {
		// TODO Auto-generated method stub
		return TYPE;
	}

	@Override
	protected void dispatch(NetNodeTreeEventHandler handler) {
		// TODO Auto-generated method stub
		switch (eventType) {
		case FETCH:
			handler.onFetchNode(this.getListNode());
			break;
		case ADD:
			handler.onAddNode(addedNode);
			break;
		case SELECT:
			handler.onItemSelection(selectedNode);
			break;
		}
	}

}
